package cn.etg.day06;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * 使用异常捕获完成下述操作
 * 将控制台输入的每一行字符串使用缓冲字符输出流PrintWriter
 * 按行以GBK编码写入到文件note.txt中
 * @author Xiloer
 *
 */
public class Test02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        FileOutputStream fos = null;
        String str ;
        OutputStreamWriter osw = null;
        BufferedWriter bw =null;
        PrintWriter pw = null;
        try {
            fos=new FileOutputStream("note.txt");
            osw=new OutputStreamWriter(fos,"GBK");
            bw=new BufferedWriter(osw);
            pw=new PrintWriter(bw);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        while(true){
            str =sc.nextLine();
            if (str.equalsIgnoreCase("exit")){
                break;
            }
            pw.println(str);
        }
        pw.close();
    }
    }
